{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e8475de2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1+1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc2125c0",
   "metadata": {},
   "source": [
    "#笔记"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "19eb96aa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\n"
     ]
    }
   ],
   "source": [
    "print('hello')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a0ae9a6b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "16f9cda9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "float"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(1.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2b56b298",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "bool"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(True)\n",
    "type(False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "440ca0a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "float(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c9a9c1c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int(1.9)#向零取整\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "67f92bf9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int(True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "aedfea77",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int(False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8b0768a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bool(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "830b6a69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bool(555)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1922885e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bool(-77)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "790510d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-2"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int(-2.9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "2730da45",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(\"hhh  hhh\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "189b201b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type('hhhhh 1')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "4af8d471",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type('''111\n",
    "1111\n",
    "1111\n",
    "\n",
    "''')#可空行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "0fa72176",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'你好年轻人'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'你好同学们'.replace('同学们','年轻人')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "4b1a75a7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'你好同学们'.find('好')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "9e17fd9f",
   "metadata": {},
   "outputs": [],
   "source": [
    "      #0 1 2 3 4 5 6\n",
    "str1=\"一二三四五六七\"\n",
    "     #-7-6-5-4-3-2-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "8fd84691",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str1.find('三')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "efa8375a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'一三五'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#str1[]  #切片： start:stop:step stop不被包含\n",
    "str1[:4]#        0\n",
    "str1[5]#索引对应文本\n",
    "str1[0:6:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "7122efce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'六'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str1[5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "1f98a7a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'一二三四'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str1[:4]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c03883e",
   "metadata": {},
   "source": [
    "转义符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "454f6e96",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I'm a girl\n"
     ]
    }
   ],
   "source": [
    "print('I\\'m a girl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "c96d827a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I'm\t a\t girl\n"
     ]
    }
   ],
   "source": [
    "print('I\\'m\\t a\\t girl')# \\n \\t \\\\ \\"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "f265ae41",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I'm a girl\n"
     ]
    }
   ],
   "source": [
    "print(\"I'm a girl\")#转义子符只占一个字符位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "79d0f0a1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I\\'m a\\ girl\n"
     ]
    }
   ],
   "source": [
    "print(\"I\\\\'m a\\\\ girl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "788ab9e3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I'm\n",
      " a\n",
      " girl\n"
     ]
    }
   ],
   "source": [
    "print(\"I'm\\n a\\n girl\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5a546301",
   "metadata": {},
   "source": [
    "列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "0e3efc2a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "list"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type([1,4,5,6])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9dd71e46",
   "metadata": {},
   "outputs": [],
   "source": [
    "List1=[1,'6','[3,4]','😊']#列表里什么都可以放"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8ce1f97e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['两', '个', '黄', '鹂', '鸣', '翠', '柳']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list('两个黄鹂鸣翠柳')#直接将字符串转成列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7d50c92c",
   "metadata": {},
   "outputs": [],
   "source": [
    "List2=list('两个黄鹂鸣翠柳')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "81f84845",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['两', '个', '黄', '鹂', '鸣', '翠', '柳', 'hh', 'hh', 'hh']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "List2.append('hh')\n",
    "List2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2e413c11",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['两', '个', '黄', '鹂', '鸣', '翠', '柳', 'hh', 'hh']"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "List2.remove('hh')\n",
    "List2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3d21213d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "List2.count('柳')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "4f120843",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['hh', 'hh', '柳', '翠', '鸣', '鹂', '黄', '个', '两']"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "List2[::]#取所有\n",
    "List2[::-1]#反向取所有"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41d35b86",
   "metadata": {},
   "source": [
    "元组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8d6cd4f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 2, [1, 23])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(1,2,[1,23])#不可修改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "dca0513f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('两', '个', '黄', '鹂', '鸣', '翠', '柳', 'hh', 'hh')"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tup=tuple(List2)\n",
    "tup"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bfcf056c",
   "metadata": {},
   "source": [
    "集合（列表可以更改，所以集合里不可放列表）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "db40b15e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{(1, 2), 1, 'k', '😁'}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#集合元素具有唯一，无序和不可改变\n",
    "{'k',(1,2),1,'😁'}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d0b0ad91",
   "metadata": {},
   "outputs": [],
   "source": [
    "set1=set(List2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "0e129e31",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "({1, 2, 3, 4, 5, 6}, {4, 5, 6, 7, 8, 9})"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "set1={1,2,3,4,5,6}\n",
    "set2={4,5,6,7,8,9}\n",
    "set1,set2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "16fa5c59",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{4, 5, 6}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#交集\n",
    "set1&set2\n",
    "set1.intersection(set2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "b2a9ea0b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3, 4, 5, 6, 7, 8, 9}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#并集\n",
    "set1|set2\n",
    "set1.union(set2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "e73d9d11",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#差集\n",
    "set1-set2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "d7833a88",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{7, 8, 9}"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "set2-set1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "cd2ae612",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3, 7, 8, 9}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#异或集合（两个差集的并集）\n",
    "set1^set2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "55aa49b2",
   "metadata": {},
   "source": [
    "操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "31b0fa02",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3, 4, 5, 6, '🤣'}"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "set1.add('🤣')\n",
    "set1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "759d337a",
   "metadata": {},
   "outputs": [],
   "source": [
    "set.remove('🤣')#删除时没有会报错"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a3560c11",
   "metadata": {},
   "outputs": [],
   "source": [
    "set.discard('🤣')#删除时没有就不执行仍然操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "1147c580",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3, 4, 5, 6, 7, 8, 9, '🤣'}"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "set1.update(set2)#把集合2加到集合1里\n",
    "set1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40983573",
   "metadata": {},
   "source": [
    "字典（键不可更改，列表不可做其键）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "3f94aae3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'姓名': 'wang', (1, 2): [1, 2, 3]}"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Dict2={'姓名':'wang',(1,2):[1,2,3]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "137c9087",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'姓名': 'kitty', '爱好': ['唱歌', 'tiaowu']}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict([['姓名','kitty'],['爱好',['唱歌','tiaowu']]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "2bc594b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "Dict1=dict([('姓名','kitty'),('爱好',['唱歌','tiaowu'])])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "deacb96c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'键2': '值2', '键1': '值1'}"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict([('键2','值2'),('键1','值1')])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "056bb9df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'姓名': 'kitty', '爱好': ['唱歌', 'tiaowu']}"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Dict1.update(Dict2)\n",
    "Dict1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "49927187",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'姓名': 'kitty', '爱好': ['唱歌', 'tiaowu']}"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Dict['姓名']='昆昆'\n",
    "Dict1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "32b188f3",
   "metadata": {},
   "source": [
    "循环"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "81e3e2f8",
   "metadata": {},
   "source": [
    "对对象进行循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "e81dee34",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['对', '象', '循', '环']"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "List1=list(\"对象循环\")\n",
    "List1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "c9693ddf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "270"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#字符串\n",
    "str1='12e34e56e78e90'\n",
    "list1=str1.split('e')\n",
    "#字符分割，int\n",
    "New_list1=[]\n",
    "for i in list1:\n",
    "    New_list1.append(int(i))\n",
    "sum(New_list1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "27810add",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "270"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ans=0\n",
    "for i in list1:\n",
    "    ans+=int(i)\n",
    "ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "ee633458",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "小李周一打卡\n",
      "小李周二打卡\n",
      "小李周三打卡\n",
      "小李周四打卡\n",
      "小李周五打卡\n"
     ]
    }
   ],
   "source": [
    "list3=['小张周一打卡','小张周二打卡','小张周三打卡','小张周四打卡','小张周五打卡']#小张换为小李\n",
    "for i in list3:\n",
    "    print(i.replace('小张','小李'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "26e69b8a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['小李周一打卡', '小李周二打卡', '小李周三打卡', '小李周四打卡', '小李周五打卡']"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list3=['小张周一打卡','小张周二打卡','小张周三打卡','小张周四打卡','小张周五打卡']#小张换为小李\n",
    "New_list3=[]\n",
    "for i in list3:\n",
    "    New_list3.append(i.replace('小张','小李'))\n",
    "New_list3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "20c61d35",
   "metadata": {},
   "source": [
    "对数据循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "2e8df643",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):    #start:0,stop,step:1\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "2a49347f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,5):    #start:0,stop,step:1  左闭右开\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "02ac9eeb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,5,2):    #start:0,stop,step:1\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14fcdae1",
   "metadata": {},
   "source": [
    "*\n",
    "**\n",
    "***\n",
    "****\n",
    "*****"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "65c53831",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*\n",
      "**\n",
      "***\n",
      "****\n",
      "*****\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,6):\n",
    "    print('*'*i)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca03be01",
   "metadata": {},
   "source": [
    "enumerate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "33288548",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 小张周一打卡\n",
      "1 小张周二打卡\n",
      "2 小张周三打卡\n",
      "3 小张周四打卡\n",
      "4 小张周五打卡\n"
     ]
    }
   ],
   "source": [
    "for i,item in enumerate(list3):\n",
    "    print(i,item)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f44b8f00",
   "metadata": {},
   "source": [
    "双重循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "1a4e776e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 0\n",
      "0 1\n",
      "0 2\n",
      "1 0\n",
      "1 1\n",
      "1 2\n",
      "2 0\n",
      "2 1\n",
      "2 2\n",
      "3 0\n",
      "3 1\n",
      "3 2\n"
     ]
    }
   ],
   "source": [
    "for i in range(4):\n",
    "    for j in range(3):\n",
    "        print(i,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "7fce7839",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 0\n",
      "1 1\n",
      "1 2\n",
      "2 0\n",
      "2 1\n",
      "2 2\n",
      "3 0\n",
      "3 1\n",
      "3 2\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,4):\n",
    "    for j in range(3):\n",
    "        print(i,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "4eed4497",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1x1=1\t\n",
      "\n",
      "2x1=2\t2x2=4\t\n",
      "\n",
      "3x1=3\t3x2=6\t3x3=9\t\n",
      "\n",
      "4x1=4\t4x2=8\t4x3=12\t4x4=16\t\n",
      "\n",
      "5x1=5\t5x2=10\t5x3=15\t5x4=20\t5x5=25\t\n",
      "\n",
      "6x1=6\t6x2=12\t6x3=18\t6x4=24\t6x5=30\t6x6=36\t\n",
      "\n",
      "7x1=7\t7x2=14\t7x3=21\t7x4=28\t7x5=35\t7x6=42\t7x7=49\t\n",
      "\n",
      "8x1=8\t8x2=16\t8x3=24\t8x4=32\t8x5=40\t8x6=48\t8x7=56\t8x8=64\t\n",
      "\n",
      "9x1=9\t9x2=18\t9x3=27\t9x4=36\t9x5=45\t9x6=54\t9x7=63\t9x8=72\t9x9=81\t\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10):\n",
    "    for j in range(1,i+1):\n",
    "        print(f'{i}x{j}={i*j}',end='\\t')\n",
    "    print('\\n')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "130feb6d",
   "metadata": {},
   "source": [
    "while可容纳更多次的循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "dd0c62ab",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-60-d3a68342de55>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m:\u001b[0m    \u001b[1;31m#死循环\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m     \u001b[1;32mpass\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "while True:    #死循环\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "08726601",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你要猜的数：4\n",
      "wrong\n",
      "请输入你要猜测的数：6\n",
      "wrong\n",
      "请输入你要猜测的数：5\n",
      "wrong\n",
      "请输入你要猜测的数：3\n",
      "wrong\n",
      "请输入你要猜测的数：2\n",
      "wrong\n",
      "请输入你要猜测的数：1\n",
      "wrong\n",
      "请输入你要猜测的数：8\n",
      "wrong\n",
      "请输入你要猜测的数：9\n",
      "wrong\n",
      "请输入你要猜测的数：0\n",
      "wrong\n",
      "请输入你要猜测的数：7\n",
      "恭喜！猜对了，就是7\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "num=random.randint(0,10)\n",
    "guess=int(input('请输入你要猜的数：'))    #int函数将一个字符串或数字转换为整型\n",
    "while guess!=num:         #!=是不等于的意思\n",
    "    print('wrong')\n",
    "    guess=int(input('请输入你要猜测的数：'))\n",
    "print(f'恭喜！猜对了，就是{num}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "73e5882f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "141\n"
     ]
    }
   ],
   "source": [
    "#1+2+3+.....\n",
    "#一共要加多少个数才能大于10000\n",
    "num=0\n",
    "var_sum=0\n",
    "while var_sum<=10000:\n",
    "    num+=1\n",
    "    var_sum+=num\n",
    "print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6699913a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
